package com.cskaoyan.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author stone
 * @date 2022/06/01 16:00
 */
// @Component
public class CustomHandlerExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
                                         Object handler, Exception e) {
        if (e instanceof ArithmeticException) {
            //处理算术异常
            return new ModelAndView("/exception.jsp");
        }
        // 如果你还要处理其他异常 → 需要你自己来写判断的业务
        return null;
    }
}
